/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tuplestoreclient;

/**
 *
 * @author Jorge
 */
public class Url {

    private int port;

    private String host;

    private int key;


    public static Url parse(String string){
        String [] strings = string.split("\\/");
        if(strings.length!=2){
            throw new RuntimeException();
        }
        String [] string1 = strings[0].split("\\:");
        if(string1.length!=2){
            throw new RuntimeException();
        }
        return new Url(Integer.parseInt(string1[1]),string1[0],Integer.parseInt(strings[1]));
    }

    protected  Url() {
    }

    public Url(int port, String host, int key) {
        this.port = port;
        this.host = host;
        this.key = key;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getKey() {
        return key;
    }

    public void setKey(int key) {
        this.key = key;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Url other = (Url) obj;
        if (this.port != other.port) {
            return false;
        }
        if ((this.host == null) ? (other.host != null) : !this.host.equals(other.host)) {
            return false;
        }
        if (this.key != other.key) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 89 * hash + this.port;
        hash = 89 * hash + (this.host != null ? this.host.hashCode() : 0);
        hash = 89 * hash + this.key;
        return hash;
    }

    public String getName(){
        return host+":"+port;
    }

    @Override
    public String toString() {
        return host+":"+port+"/"+key;
    }




}
